/**
 * Created by cici on 2016-05-30.
 */



//生成样式
exports.makeStyle = function(style,css){
    var rs = {};
    $.each(style,function(i,t){
        if(t || t == 0){
            if(t.constructor != Object){

                switch (i) {
                    default :
                        rs[i] = exports.autoPX(i,t);
                        break;
                }
            }
        }
    });
    return rs;
};

//样式值加PX
exports.autoPX = function(name,val){
    var rs = val;
    switch(name){
        case 'width':
        case 'maxHeight':
        case 'height':
        case 'top':
        case 'bottom':
        case 'left':
        case 'right':
        case 'lineHeight':
        case 'fontSize':
        case 'paddingTop':
        case 'paddingBottom':
        case 'paddingLeft':
        case 'paddingRight':
        case 'marginTop':
        case 'marginBottom':
        case 'marginLeft':
        case 'marginRight':
        case 'borderWidth':
        case 'borderTopWidth':
        case 'borderBottomWidth':
        case 'borderLeftWidth':
        case 'borderRightWidth':
            if(val != 'auto' && val != undefined){
                if(_.isString(val)){
                    if(val.lastIndexOf('%') == -1){
                        //val = val == '' ? 0 : val;
                        rs = val + 'px';
                    }
                }else{
                    rs = val + 'px';
                }

            }
            break;

        case 'backgroundImage':
            rs = 'url(' + val + ')';
            break;

    }
    return rs;
};


exports.gethtmlspecialchars = function(str){
    str = str.replace(/&amp;/g, '&');
    str = str.replace(/&lt;/g, '<');
    str = str.replace(/&gt;/g, '>');
    str = str.replace(/&quot;/g, '"');
    str = str.replace(/&#039;/g, "'");
    return str;
};

exports.sethtmlspecialchars = function(str){
    str = str.replace(/\n/g,'<br \/>');
    str = str.replace(/&/g, '&amp;');
    str = str.replace(/</g, '&lt;');
    str = str.replace(/>/g, '&gt;');
    str = str.replace(/"/g, '&quot;');
    str = str.replace(/'/g, '&#039;');
    return str;
};


exports.type2name = function (type) {
    var name = '';
    switch (type){
        case 'MM':
            name = '眉妆';
            break;

        case 'YY':
            name = '眼影';
            break;

        case 'KH':
            name = '唇妆';
            break;

        case 'YX':
            name = '眼线';
            break;

        case 'JM':
            name = '睫毛';
            break;

        case 'SH':
            name = '腮红';
            break;
    }
    return name;
};
